﻿using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace KinonekoSoftware.Studio.Resources.Converters
{
    public sealed class FindGeometryByNameConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values is null || values.Length < 1)
            {
                return null;
            }

            var fe   = values[0] as FrameworkElement;
            var name = values[1]?.ToString();

            if (string.IsNullOrEmpty(name))
            {
                return null;
            }

            var i = fe?.FindResource(name);
            return i;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}